package kz.kstu.scantest.desktop.ui.dialog;

import kz.kstu.scantest.desktop.util.GUIUtils;

import javax.swing.*;
import java.awt.event.*;

public class ProgressDialog extends JDialog {

    private static final int WIDTH = 400;
    private static final int HEIGHT = 150;

    private JPanel contentPane;
    private JButton cancelButton;
    private JProgressBar progressBar;
    private boolean isCanceled;

    public ProgressDialog() {

    }

    public void initStaticComponents() {
        setContentPane(contentPane);
        setModal(true);
        this.setSize(WIDTH, HEIGHT);
        progressBar.setIndeterminate(true);
        initListeners();
        cancelButton.setVisible(false);
        GUIUtils.centerAndShow(this);
    }

    private void initListeners() {
        cancelButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onCancel();
            }
        });

        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    }

    private void onCancel() {
        isCanceled = true;
        dispose();
    }

    public boolean isCanceled() {
        return isCanceled;
    }
}
